<?php
namespace app\controller\demo;

use think\Controller;

class Application extends Controller
{
    /**
     * 前置执行的method
     * @var array
     */
    protected $beforeActionList = [
        'begin',
        //'middle' =>  ['except'=>'hello'],
        //'end'  =>  ['only'=>'hello,data'],
    ];

    protected function begin()
    {
        if (! config('app.app_debug')) {
            json($this->formatResult(-1, 'only allow local environment'))->send();
            exit;
        }
        $this->assign('title', 'Demo');
    }

    public function formatResult($ret, $msg, $data = [])
    {
        return ['ret' => $ret, 'msg' => $msg, 'data' => $data];
    }
}